﻿@using Shop.Entity;
@using Shop.Help;
@using Shop.Bll;
@using System.Data;
@using Shop.Help;
@using Webdiyer.WebControls.Mvc;
@{
    Layout = null;
    string serverPath = Safe.GetWebConfigValueByKey("ServerPath");
}
@model  PagedList<DataRow>
@{

}

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>列表</title>
    <link href="@Url.Content("/Content/admin/css/bootstrap.min.css")" rel="stylesheet" />
    <script src="/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Content/MvcPager/MvcPager.js"></script>
</head>
<body>
    <ol class="breadcrumb">
        <li><a href="/set/admin/center">首页></a></li>
        <li><a href="#">积分换礼></a></li>
        <li class="active">礼品管理</li>
    </ol>

    <div class="portlet-body">


        <div class="navbar-form navbar-left" role="search">

            <a class="btn btn-primary btn-sm " data-toggle="modal" href="/gift/gift/add"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;新增</a>
            <button type="submit" class="btn btn-primary btn-sm " id="checkAll" onclick="CheckAll(this);">
                <span class="glyphicon glyphicon-check" aria-hidden="true">全选</span>
            </button>
            <button type="submit" class="btn btn-primary btn-sm" onclick="Delete(null, '/gift/gift/delete', '/gift/gift/list/@(Model.CurrentPageIndex - 1 > 1 ? Model.CurrentPageIndex - 1 : 1)');">
                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;删除
            </button>
        </div>

        <form class="navbar-form navbar-left" id="formSearch" role="form" action="/gift/gift/list">
            <input type="hidden" name="PageSize" value="10" />
            <div class="form-group">
                @Html.DropDownList("CateGory", (List<SelectListItem>)ViewData["CateGory"], "-选择类别-", new { id = "Category", @class = "form-control input-sm" })
            </div>
            <div class="form-group">
                @Html.DropDownList("Business", ViewData["Business"] as IEnumerable<SelectListItem>, "-选择商户-", new { id = "Category", @class = "form-control input-sm" })
            </div>
            <div class="form-group">
                <input type="text" class="form-control input-sm" id="SearchTitle" name="title" placeholder="请输入抢购标题" />
            </div>
            <button type="submit" class="btn btn-primary btn-sm ">
                <span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>&nbsp;搜索
            </button>
        </form>
        <div id="divTable">
            <table class="table table-bordered  table-condensed table-condensed  table-condensed table-hover">
                <thead>
                    <tr>
                        <th></th>
                        <th>名称</th>
                        <th>归属商户</th>
                        <th>封面图</th>
                        <th>类别</th>
                        <th>所需积分</th>
                        <th>单人限兑</th>
                        <th>状态</th>
                        <th>总数</th>
                        <th>兑换数</th>
                        <th>排序</th>
                        <th>创建时间</th>
                        <th class="hidden-xs">操作</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (DataRow item in Model)
            {
                        <tr>
                            <td>
                                <input type="checkbox" name="subBox" value="@item["Guid"]" id="ck@(item["Guid"])" />
                            </td>
                            @if (item["Name"].ToString().Length >= 20)
                            {
                                <td class="title" id="@item["Guid"]" onmouseover="ShowMsg('@item["Guid"]','@item["Name"]')">@item["Name"].ToString().Substring(0, 20)  ...</td>
                            }
                            else
                            {
                                <td class="title">@item["Name"]</td>
                            }
                            <td>@item["BusinessName"]</td>
                            <td style="padding: 5px;">
                                <img onmouseover="MouseShowImage(this);" style="height:25px;width:40px;" alt="" src="@item["Image"]" onerror="this.src = '/Content/noImg.jpg';" />
                            </td>

                            <td>@item["Title"]</td>
                            <td>@item["Point"]</td>
                            <td>@item["SingleLimit"]</td>
                            @switch (item["Status"].ToString())
                            {
                                case "0":
                                    <td>已上架</td>
                                    break;
                                case "1":
                                    <td>已下架</td>
                                    break;
                                case "2":
                                    <td>已售罄</td>
                                    break;
                                default:
                                    <td>@item["Status"]</td>
                                    break;

                            }
                            <td>@item["StockCount"]</td>
                            <td>@item["ExchangeCount"]</td>
                            <td>@item["Sort"]</td>
                            <td>@Convert.ToDateTime(item["CreateTime"]).ToString("yyyy-MM-dd hh:mm:ss")</td>
                            <td>

                                <a class="btn btn-default btn-xs" title='编辑' href="/gift/gift/add/@item["Guid"]?pageIndex=@Model.CurrentPageIndex">编辑</a>
                                <a class="btn btn-default btn-xs" title='若已存在订则单不能删除' onclick="Delete('@item["Guid"]','/groupbuy/groupbuy/delete','/articleinfo/article/list/@(Model.CurrentPageIndex - 1 > 1 ? Model.CurrentPageIndex - 1 : 1)');">删除 </a>

                            </td>
                        </tr>
                    }
                </tbody>
            </table>
            <div class="col-xs-9" style="width:auto;padding-left:0px;">
                <ul class="pagination">
                    <li>
                        <span aria-hidden="true">
                            @(Model.PageSize)条/页，@(Model.TotalPageCount)页, 共@(Model.TotalItemCount)条
                        </span>
                    </li>
                    <li>
                        <span aria-hidden="true">
                            每页
                            <select style="border-radius:4px;font-family:normal;vertical-align: text-bottom;" id="PageSize" name="PageSize" onchange="PageSizeChange();">
                                <option value="10">10</option>
                                <option selected="selected" value="15">15</option>
                                <option value="20">20</option>
                            </select>
                            条
                        </span>
                    </li>
                </ul>
                @Ajax.Pager(Model,
        new PagerOptions
        {
            PageIndexParameterName = "id",
            CssClass = "pagination",
            FirstPageText = "首页",
            LastPageText = "尾页",
            PrevPageText = "上一页",
            PageIndexBoxId = "pageIndexBox",
            GoToButtonId = "Go",
            PageIndexOutOfRangeErrorMessage = "页码有误!",
            NumericPagerItemCount = 8,
            NextPageText = "下一页",
            CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>",
            DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>",
            PagerItemTemplate = "<li>{0}</li>",
            AutoHide = false,

        }, new MvcAjaxOptions
        {
            UpdateTargetId = "divTable",
            HttpMethod = "Post",
            DataFormId = "formSearch",
            EnableHistorySupport = false,
            OnSuccess = "Success();"
            //EnablePartialLoading = true
        }
        )
            </div>
            <div class="pagination" style="width:20%;margin-top: 0px;">
                <ul class="pagination">
                    <li>
                        <div class="input-group">
                            <span class="input-group-addon">第</span>
                            <input type="text" id="pageIndexBox" class="form-control input-sm" placeholder="" aria-describedby="sizing-addon2" oninput="InputPageIndex(this);">
                            <span class="input-group-addon">页</span>
                            <span class="input-group-btn">
                                <button class="btn btn-primary btn-sm" id="Go" type="button">Go</button>
                            </span>
                        </div>
                    </li>
                </ul>
            </div>
            <script type="text/javascript">
                function Success()
                {
                    var txt = $("#SearchTitle").val().trim();
                    if (txt.length > 0)
                    {
                        $(".title").each(function ()
                        {
                            var newTxt = $(this).html().replace(txt, txt.fontcolor("red"));
                            $(this).html(newTxt);
                        });
                    }

                    $("input[name='PageSize']").val('@ViewData["NowPageSize"]');
                    $("#PageSize").val(@ViewData["NowPageSize"]);
                }
            </script>
        </div>
        @{Html.RegisterMvcPagerScriptResource();}
        <script src="/Content/layer/layer.js"></script>
        <script src="/Content/LwsJS/List.js"></script>
        <script type="text/javascript">
            function ShowMsg(id, msg)
            {
                layer.tips(msg, "#" + id, {
                    tips: [2, '#3595CC'],
                    time: 4000
                });
                $("#" + id).mouseout(function ()
                {
                    layer.closeAll('tips'); //关闭所有的tips层
                });
            }
            function MouseShowImage(obj)
            {
                layer.open({
                    type: 5,
                    title: false,
                    closeBtn: 0,
                    shade: 0,
                    content: "<img src='" + $(obj).attr("src") + "'/>"
                });
                $(obj).mouseout(function ()
                {
                    layer.closeAll();
                });
            }
            function InputPageIndex(obj)
            {
                var pageIndex = $(obj).val().trim();
                if (parseInt(pageIndex) > parseInt($("#TotalPageCount").val()))
                {
                    $(obj).val($("#TotalPageCount").val());
                }
            }
            function PageSizeChange()
            {
                $("input[name='PageSize']").val($("#PageSize").val());
                $("#formSearch").submit();
            }
            function GoPageIndex()
            {
                var pager = Webdiyer.MvcPagers[0];
                var pageIndex = $("#pageIndexBox").val().trim();
                var TotalPageCount = $("#TotalPageCount").val().trim();
                if (parseInt(pageIndex) > parseInt(TotalPageCount))
                {
                    pageIndex = TotalPageCount;
                }
                if (pager != null)
                {
                    pager.goToPage(parseInt(pageIndex));
                } else
                { alert("找不到指定的MvcPager！"); }
            }
        </script>
    </div>
</body>
</html>